package com.qeado.admin.dao.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.qeado.admin.dao.AdminAccountManageDao;
import com.qeado.admin.model.AdminAccount;
import com.qeado.admin.model.Menu;
import com.qeado.admin.model.Role;
import com.qeado.common.dao.BaseDao;

@Repository
@SuppressWarnings("unchecked")
public class AdminAccountManageDaoImpl extends BaseDao implements AdminAccountManageDao{
	public AdminAccount validateUser(String loginName, String password) {
        Map userMap = new HashMap();
        userMap.put("loginName", loginName);
        userMap.put("password", password);
        return (AdminAccount)getSqlMapClientTemplate().queryForObject("validateUser", userMap);
    }

    public List getMenuListByUser(AdminAccount userInfo) {
        return getSqlMapClientTemplate().queryForList("getMenuListByUser", userInfo);
    }

	public List<Menu> getMenuListByMenuIdAndRoleId(Map<String, String> map) {
        return getSqlMapClientTemplate().queryForList("getMenuListByMenuIdAndRoleId", map);
	}

    public void saveUserInfo(AdminAccount userInfo) {
        getSqlMapClientTemplate().insert("saveUserInfo", userInfo);
    }

    public void updateUserInfo(AdminAccount userInfo) {
        getSqlMapClientTemplate().update("updateUserInfo", userInfo);
    }

    public void updateUserPassword(AdminAccount userInfo) {
        getSqlMapClientTemplate().update("updateUserPassword", userInfo);
    }

    public List searchAdminAccount(AdminAccount account) {
        return getSqlMapClientTemplate().queryForList("searchAdminAccount", account);
    }

    public AdminAccount searchAdminAccountById(String id) {
        return (AdminAccount)getSqlMapClientTemplate().queryForObject("searchAdminAccountById", id);
    }

    public void saveAdminAccount(AdminAccount account) {
        getSqlMapClientTemplate().insert("saveAdminAccount", account);
    }	
	public String searchAdminAccountByName(AdminAccount account) {
		return (String)getSqlMapClientTemplate().queryForObject("searchAdminAccountByName", account);
	}

    public void updateAdminAccount(AdminAccount account) {
        getSqlMapClientTemplate().update("updateAdminAccount", account);
    }

    public void deleteAdminAccount(String id) {
        getSqlMapClientTemplate().update("deleteAdminAccount", id);
    }

	public List<Role> searchRoleList() {
		return getSqlMapClientTemplate().queryForList("searchRole");
	}

	public void deleteAdminAccountRole(Map<String, String> map) {
		getSqlMapClientTemplate().delete("deleteAdminAccountRole", map);
	}

	public void saveAdminAccountRole(Map<String, String> map) {
		getSqlMapClientTemplate().insert("saveAdminAccountRole", map);
	}

	@Override
	public Object validateOldpassword(AdminAccount account) {
		return getSqlMapClientTemplate().queryForObject("validateOldpassword", account);
	}

	@Override
	public Object searchAccountRole(AdminAccount account) {
		return getSqlMapClientTemplate().queryForObject("searchAccountRole", account);
	}

}
